
import java.util.StringTokenizer;
import java.util.regex.Pattern;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author root
 */
public class TEST {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {

    }

    private static byte[] concatenateByteArrays(byte[] a1, byte[] a2, int len) {
        byte[] b = new byte[len];
        int a1Len = a1.length;
        if (a1Len > len) { a1Len = len; }
        for (int i = 0; i < a1Len; ++i) {
            b[i] = a1[i];
        }
        for (int i =0; i < (len - a1Len); ++i) {
            b[a1Len + i] = a2[i];
        }
        return b;
    }

     /**
      * Convert a byte[] array to readable string format. This makes the "hex" readable!
      * @return result String buffer in String format
      * @param in byte[] buffer to convert to string format
      */
    static String byteArrayToHexString(byte in[]) {
        byte ch = 0x00;
        int i = 0;
        if (in == null || in.length <= 0) return null;
        String pseudo[] = {"0", "1", "2", "3", "4", "5", "6", "7",
                           "8", "9", "A", "B", "C", "D", "E", "F"};
        StringBuffer out = new StringBuffer(in.length * 2);
        while (i < in.length) {
            ch = (byte) (in[i] & 0xF0); // Strip off high nibble
            ch = (byte) (ch >>> 4); // shift the bits down
            ch = (byte) (ch & 0x0F); // must do this is high order bit is on!
            out.append("0x");
            out.append(pseudo[ (int) ch]); // convert the nibble to a String Character
            ch = (byte) (in[i] & 0x0F); // Strip off low nibble
            out.append(pseudo[ (int) ch]); // convert the nibble to a String Character
            out.append(" ");
            i++;
        }

        String rslt = new String(out);

        return rslt;

    }

    public static byte[] hexStringToByteArray(String s) {
        StringTokenizer st = new StringTokenizer(s);
        byte[] b = new byte[st.countTokens()];
        for (int i = 0; i < b.length; ++i) {
            b[i] = Integer.decode(st.nextToken()).byteValue();
        }
        return b;
    }

}
